package com.mf.cloud.controller;

import com.mf.cloud.entities.Pay;
import com.mf.cloud.resp.ResultData;
import com.mf.cloud.service.PayService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * ClassName: PayController
 * Package: com.mf.cloud.controller
 *
 * @Author: lmf
 * @Create: 2024/3/3 15:15
 * @Version: 1.0
 * Description:支付控制层
 */
@RestController  // 返回JSON格式响应体
@RequestMapping("/pay")
@Slf4j
@Tag(name = "支付")
public class PayController {
    @Resource
    private PayService payService;
    @Operation(summary = "新增")
    @PostMapping("/add")
    public ResultData<Integer> add(@RequestBody Pay pay){
        return ResultData.success(payService.add(pay));
    }
    @Operation(summary = "删除")
    @GetMapping("/del/{id}")
    // @PathVariable 获取路径上占位符的值
    public ResultData<Integer> delete(@PathVariable("id") Integer id){
        System.out.println(id);
        return ResultData.success(payService.delete(id));
    }
    @Operation(summary = "更新")
    @PostMapping("/update")
    public ResultData<Integer> update(@RequestBody Pay pay){
        return ResultData.success( payService.update(pay));
    }
    @Operation(summary = "查询全部")
    @GetMapping("/all")
    public ResultData<List<Pay>> getAll(){
        return ResultData.success(payService.getAll());
    }
    @Operation(summary = "根据id查询")
    @GetMapping("/select/{id}")
    public ResultData<Pay> selectById(@PathVariable("id") Integer id){
        try {
            TimeUnit.SECONDS.sleep(66);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return ResultData.success(payService.selectById(id));
    }

    @Value("${server.port}")
    private String port;
    @GetMapping("get/info")
    public String getInfoByConsul(@Value("${mf.info}") String mfInfo){
        return "mfInfo: " + mfInfo+"\t"+"port"+port;
    }
}
